package service;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
/*
* HttpServletRequest req
*HttpServletResponse resp
* 都是服务器创建的，直接拿来用，req封装了请求消息的内容，
*  */
@WebServlet("/demo3")
public class ServletDemo3 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    /*1.获取请求方式
    * String getMethod();
    * */
        String method = req.getMethod();
        System.out.println(method);
        /*2.虚拟目录
        *String getContextPath();
        * */
        String contextPath = req.getContextPath();
        System.out.println(contextPath);
        /*3.获取servlet路径 资源路径
        *String getServletPath()
        * */
        String servletPath = req.getServletPath();
        System.out.println(servletPath);
    /*4.获取get方式请求参数 name=zhangsan
    *String getQueryString()
    * */
        String queryString = req.getQueryString();
        System.out.println(queryString);
        /*5.获取请求uri：/untitled001/demo3
        * String getRequestURI()*/
        String requestURI = req.getRequestURI();
        StringBuffer requestURL = req.getRequestURL();
        System.out.println(requestURI);
        System.out.println(requestURL);
        /*
        * uri:统一资源标识符/untitled001/demo3
        * url：统一资源定位符http://localhost:8080/untitled001/demo3
        * */
    }
}
